package com.bjt.wms.sys.common;

import com.bjt.common.constant.BaseConstant;
import com.bjt.utils.BaseUtil;
import com.jfinal.core.Controller;
import com.jfinal.upload.UploadFile;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class BaseUploadController extends Controller {

    /**
     * 获取上传的图片并返回路径集合
     *
     * @param count 图片数
     * @param type  inboud 入库  outbound 出库
     * @return
     */
    public List getPhotoList(int count, String type) {
        List<String> paths = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            String path = BaseConstant.UPLOAD_PATH + type + File.separator + BaseUtil.generateUUID() + ".png";

            UploadFile uploadFile = getFile("photo" + i);
            uploadFile.getFile().renameTo(new File(path));

            paths.add(path);
        }
        return paths;
    }
}
